from typing import List

class Solution:
    def evaluate(self, s: str, knowledge: List[List[str]]) -> str:
        knowledge_dict = {}
        for i in knowledge:
            knowledge_dict[i[0]] = i[1]
        print(knowledge_dict)
        flag = False
        key = ""
        s_all = ""
        for i in s:
            if i == '(':
                flag = True
                continue
            if i ==')':
                flag = False
                if key in knowledge_dict:
                    s_all += knowledge_dict[key]
                else:
                    s_all += '?'
                key = ""
                continue
            if flag:
                key += i

            if not flag:
                s_all +=i
        return s_all

if __name__ == '__main__':
    s = "(name)is(age)yearsold"
    knowledge = [["name", "bob"], ["age", "two"]]
    solution = Solution()
    val = solution.evaluate(s,knowledge)
    print(val)

